import urllib.request
import urllib.parse

init_url = "https://fanyi.baidu.com/sug"
word = input("请输入单词:")
form_data = { "kw":word,}
form_data = urllib.parse.urlencode(form_data).encode()

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) \
    Chrome/63.0.3239.132 Safari/537.36X-Requested-With: XMLHttpRequest",}
try:
    request = urllib.request.Request(init_url,headers)
    response = urllib.request.urlopen(request,form_data)

    temp_json = eval(response.read().decode())
    tran_word = temp_json['data']
    print("The word means:",tran_word[0]['v'])

except IndexError:
    print("input error!please input again.....")